<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
	<base href="${pageContext.request.contextPath}/">
	<title>Title</title>
	<link rel="stylesheet" href="assets/layui/css/layui.css">
	<link rel="stylesheet" href="assets/css/base.css">
	<style>

	</style>
</head>
<body>
<div class="page">
	<form class="layui-form  fx-col" id="form" lay-filter="form_filter" >

		<div class="layui-form-item">
			<label class="layui-form-label">请选择要上传的文件</label>
			<div class="layui-input-block">
				<input type="file" name="file"  required  lay-verify="required"
					   autocomplete="off" class="layui-input" id="file">
			</div>

		</div>

		<blockquote class="layui-elem-quote">
			请先 <a href="student/downloadModel">点击这里</a> 下载导入模板，填写完数据后，通过上方按钮选择文件完成导入

		</blockquote>


		<button  lay-submit="" class="layui-btn mt-15" id="save_btn" type="button">保存</button>
	</form>
</div>


</body>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="assets/layui/layui.all.js"></script>

<script>
	$(function () {
		//监听提交
		layui.form.on('submit()', function(data){

			let formData = new FormData();
			formData.append("file", $("#file")[0].files[0]);

			$.ajax({
				url: "student/upload",
				type: "post",
				data: formData,
				contentType: false,
				processData: false,
				dataType: "json",
				success(res) {
					if (res.success) {
						layer.msg('保存成功', {icon: 6}, function () {
							window.parent.search();
						});

					} else {
						layer.msg(res.msg, {icon: 2});
					}
				}

			})
			return false;
		});
	})
</script>
</html>
